FROM node:lts-alpine3.13

ENV REPO_URL=https://gitee.com/liyvhg/jdhello-world_jd_scripts.git
ENV SHELL_REPO_URL=https://gitee.com/lmorething/jd-scripts.git
ENV scripts_dir=/jd/jdTool
ENV shell_dir=/jd/docker
ENV ENABLE_HANGUP=true
ENV ENABLE_WEB_PANEL=true
ENV JD_DIR=/jd
# 不存在则自动创建
WORKDIR /jd

RUN set -ex  \
    && sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories \
    && apk update \
    && apk upgrade \
    && apk add --no-cache bash tzdata git moreutils curl jq openssh-client python3\
    && python3 -m ensurepip --default-pip \
    && pip3 install --no-cache-dir pyyaml \
    && rm -rf /var/cache/apk/* \
    && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && echo "Asia/Shanghai" > /etc/timezone \
    && npm config set registry https://registry.npm.taobao.org \
    && mkdir -p /root/.ssh \
    && git clone $REPO_URL $scripts_dir \
    && mkdir config\
    && git clone ${SHELL_REPO_URL} ${shell_dir} \
    && cp ${shell_dir}/endpoint.sh /jd \
    && chmod +x /jd/endpoint.sh \
    && cp ${shell_dir}/update_js.sh /jd \
    && chmod +x /jd/update_js.sh \
    && cp ${shell_dir}/rm_log.sh /jd \
    && chmod +x /jd/rm_log.sh \
    && cp ${shell_dir}/export_sharecodes.sh /jd \
    && chmod +x /jd/export_sharecodes.sh \
    && cp ${shell_dir}/update.js /jd \
    && cp ${shell_dir}/sendNotify.js ${scripts_dir} \
    && cp ${shell_dir}/package-lock.json ${scripts_dir} \
    && cp ${shell_dir}/jd.sh /jd \
    && chmod +x /jd/jd.sh \
    && cd $scripts_dir \ 
    && npm install \
    && cp -r ${shell_dir}/panel /jd \
    && cd ${JD_DIR}/panel \
    && npm install \
    && npm install -g pm2

CMD [ "sh", "endpoint.sh" ]